package kr.pe.johnkim.pushchat.mobile.controller;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatLog;
import kr.pe.johnkim.pushchat.mobile.service.PushChatLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 6. 12.
 */
@Controller
@RequestMapping(value = "/pushChatLogController")
public class PushChatLogController {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatLogController.class);

    @Autowired
    private PushChatLogService pushChatLogService;

    /**
     * 로그를 등록 한다.
     *
     * @param pushChatLog
     * @throws Exception
     */
    @RequestMapping(value="/registerLog", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public void registerLog(@RequestBody PushChatLog pushChatLog) throws Exception {
        logger.info("registerLog");

        try {
            this.pushChatLogService.registerLog(pushChatLog);
            logger.info("success to register log.");
        } catch (Exception e) {
            logger.error("fail to register log.");
        }
    }

    /**
     * 로그 목록을 가져 온다.
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/selectLogList", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public List<PushChatLog> selectLogList() throws Exception {
        logger.info("selectLogList");
        return this.pushChatLogService.selectLogList();
    }
}
